/**
 * 轮播图
 */
let mySwiper = new Swiper('.swiper', {
    autoplay: {
        delay: 3000,
        stopOnLastSlide: false,
        disableOnInteraction: false,
    },
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },

    loop: true,
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
})

// 事件注册 鼠标移入事件
$('.swiper').addEventListener('mouseover', function() {
    $('.swiper-button-prev').style.opacity = '0.5';
    $('.swiper-button-next').style.opacity = '0.5';

})

$('.swiper').addEventListener('mouseout', function() {
    $('.swiper-button-prev').style.opacity = '0';
    $('.swiper-button-next').style.opacity = '0';
})

// 事件注册 鼠标移入事件
$('.swiper-button-prev').addEventListener('mouseover', function() {
    this.style.background = 'rgba(0, 0, 0, .6)';
})
$('.swiper-button-next').addEventListener('mouseover', function() {
    this.style.background = 'rgba(0, 0, 0, .6)';
})

//事件注册 鼠标移出事件
$('.swiper-button-prev').addEventListener('mouseout', function() {
    this.style.background = 'rgba(0, 0, 0, .3)';
})
$('.swiper-button-next').addEventListener('mouseout', function() {
    this.style.background = 'rgba(0, 0, 0, .3)';
})

// 定义变量保存图片名称
let pathName = '';
$a('.employ li').forEach(function(v) {
    //事件注册 鼠标移入事件
    // console.log(v);
    v.addEventListener('mouseover', function() {

        //获取图片路径
        let son = v.firstElementChild;
        let son1 = son.firstElementChild;
        // console.log(son1);
        let path = son1.src;
        // console.log(path);

        //查找.和/的位置
        let index1 = path.lastIndexOf('/');
        let index2 = path.lastIndexOf('.');

        //截取路径
        pathName = path.slice(index1 + 1, index2);

        //设置图片的路径
        son1.src = `../../assets/imgs/${pathName}-c.svg`;

        v.style.backgroundColor = '#2e7ee9';
    })

    // 事件注册 鼠标移出事件
    v.addEventListener('mouseout', function() {
        v.style.backgroundColor = ''
        let son = v.firstElementChild;
        let son1 = son.firstElementChild;
        let path = son1.src;
        son1.src = `../../assets/imgs/${pathName}.svg`;
    })
})


//行业巨头 走马灯效果
//定义索引
let index = 0;
setInterval(function() {
    //先清除原来的类名
    $a('.item')[index].classList.remove('active')

    //索引自增
    ++index;

    if (index >= $a('.item').length) {
        index = 0;
    }

    //给当前添加类名
    $a('.item')[index].classList.add('active')
}, 3000)


//回到顶部
// console.log(backTop);
//事件注册 窗口滚动事件
window.addEventListener('scroll', function() {
    if (this.window.scrollY >= 500) {
        $('.button').style.display = 'block';
    } else {
        $('.button').style.display = 'none';
    }
})

//事件注册 点击事件
$('.button').addEventListener('click', function() {
    // console.log(1);
    //定义滚动到浏览器滚动到指定的位置 
    window.scrollTo({
        //三个属性 left top behavior
        left: 0,
        top: 0,
        behavior: 'smooth' //平滑滚动，不写的话默认auto
    })
})